package com.ah.servlet;
import java.io.IOException;
import java.util.Enumeration;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebInitParam;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
// 笔记：
// 写了service方法，就不走doGet和doPost方法；不写就走（配置版是走了doXX，再走service）
// (urlPatterns = { "/Servlet3", "/Servlet3_0" }),两个url都能触发本Servlet
// getServletConfig为空!!!
// 默认生成的注解是：
// @WebServlet("/Servlet3_0")
@WebServlet(name = "Servlet3.0", urlPatterns = { "/Servlet3", "/Servlet3_0" }, initParams = {
		@WebInitParam(name = "para1", value = "Apple"),
		@WebInitParam(name = "para2", value = "Banana") })
public class Servlet3_0 extends HttpServlet {
	private static final long serialVersionUID = 1L;
	public Servlet3_0() {
		super();
	}
	public void init(ServletConfig config) throws ServletException {
		System.out.println("===init===");
		Enumeration<String> paraNames = config.getInitParameterNames();
		while (paraNames.hasMoreElements()) {
			String paraName = paraNames.nextElement();
			String paraValue = config.getInitParameter(paraName);
			System.out.println("【@WebInitParam】=" + paraName + ":" + paraValue);
		}
	}
	protected void service(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		System.out.println("service方法");
	}
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		System.out.println("Servlet3.0,Get方法");
	}
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		System.out.println("Servlet3.0,Post方法");
	}
}
